<?php
namespace app\api\controller;

use app\api\controller\Api;
use app\common\model\Article as ArticleCommonModel;
use app\common\model\ArticleCat;
use think\facade\Request;

class Article extends Base
{
    /*
     * @name 展示文章
     * @return json articlelist
     **/
    public function articleList($value = '')
    {
        $articlelist = ArticleCommonModel::order('art_addtime', 'desc')->select();
        foreach ($articlelist as $k => $v) {
            $articlelist[$k]['cat_name'] = ArticleCat::where('cat_id', $v['art_cat_id'])->value('cat_name');
            $articlelist[$k]['art_img'] = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/'.$v['art_img'];
        }
        return $this->getOutput(200, 'ok', $articlelist);
    }

    public function getContentById(){
        $id = $this->request->param('art_id');
        $content = ArticleCommonModel::where('art_id' ,$id)->value('art_content');
        return $this->getOutput(200, 'ok', $content);
    }
}
